<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('Trunk/item_save')}" method="post" data-success-fn="show_reload_tip()">
        <table>
            <tr><th>中继模式：</th><td>
                    <input type="radio" name="regMode" checked="checked" value='register'>注册模式
                    <input type="radio" name="regMode" value='ip'>IP模式
                    <input type="radio" name="regMode" value='ims'>IMS模式
                </td>
            </tr>
            <if condition="$isSuperAdmin">
                <th>租户ID：</th><td>
                    <select name="siteID" title="请选择租户" required data-url="{:AddonU('Admin/get_admin_json')}" data-value="{$data.siteID}"></select>
                <else/>
                <tr style="display: none;">
                <input type="hidden" name="siteID" value="{$loginData.siteID}"/>
                </td></tr>
            </if>
            <tr>
                <th>注册服务器：</th><td>
                    <input type="text" name="host" placeholder="服务器地址" value="{$data.host}"/>
                    <a href="#" onclick="return ansy_val('fromdomain', this);">[设置]</a>
                </td></tr>
            <tr>
                <th>注册端口号：</th><td>
                    <input type="text" name="port" placeholder="端口号,如5060" value="{$data.port}"/>
                </td></tr>
            <tr>
                <th>中继名称：</th><td>
                    <input type="text" name="account" placeholder="中继名称(account)" value="{$data.account}"
                           title="请填写中继名称(CtiID|组号码)!"/>
                    <a href="#" onclick="return ansy_val('accountcode', this);">[设置]</a>
                </td></tr>
            <tr>
                <th>用户名：</th><td>
                    <input type="text" name="username" placeholder="用户名(username)" value="{$data.username}" />
                    <a href="#" onclick="return ansy_val('fromuser', this);">[设置]</a>
                </td></tr>
            <tr>
                <th>密码：</th><td>
                    <input type="password" name="password" placeholder="密码" title="请填写6-16个字符!"/>
                </td></tr>
            <tr>
                <th>注册数量：</th><td>
                    <input type="text" name="regNumber" placeholder="注册数量" value="{$data.regNumber|default='0'}"
                           title="请填写数字!"/>
                </td></tr>       
        </table>
        <fieldset class="optional" data-func="setRegModeUI()">
            <legend>更多选项<i>[+]</i></legend>
            <table class="optional_content">
                <tr>
                    <th>type：</th><td>
                        <select name='type' required title="请填写type!">
                            <option value='peer' selected='selected'>peer</option>
                            <option value='friend'>friend</option>
                        </select>
                    </td></tr>
                <tr>
                    <th>nat：</th><td>
                        <input type="radio" name="nat" value="yes" checked="checked" required/>是
                        <input type="radio" name="nat" value="no" required/>否
                    </td></tr>
                <tr>
                    <th>accountcode：</th><td>
                        <input type="text" name="accountcode" placeholder="accountcode" value="{$data.accountcode}"/>
                    </td></tr>
                <tr>
                    <th>fromdomain：</th><td>
                        <input type="text" name="fromdomain" placeholder="fromdomain" value="{$data.fromdomain}" size="30"/>
                    </td></tr>
                <tr>
                    <th>fromuser：</th><td>
                        <input type="text" name="fromuser" placeholder="fromuser" value="{$data.fromuser}"/>
                    </td></tr>
                <tr>
                    <th>context：</th><td>
                        <input type="text" name="context" placeholder="context" value="{$data.context|default='my-internal'}"/>
                    </td></tr>
                <tr>
                    <th>insecure：</th><td>
                        <input type="text" name="insecure" placeholder="insecure" value="{$data.insecure|default='port,invite,very'}"/>
                    </td></tr>
                <tr>
                    <th>defaultexpiry：</th><td>
                        <input type="text" name="defaultexpiry" placeholder="注册超时时间(s)" value="{$data.defaultexpiry|default='120'}"/>
                    </td></tr>
                <tr>
                    <th>dtmfmode：</th><td>
                        <select name='dtmfmode' title="请选择dtmfmode">
                            <option value='rfc2833' selected='selected'>rfc2833</option>
                            <option value='inband'>inband</option>
                            <option value='info'>info</option>
                            <option value='auto'>auto</option>
                        </select>
                    </td></tr>
                <tr>
                    <th>disallow：</th><td>
                        <input type="text" name="disallow" placeholder="disallow" value="{$data.disallow|default='all'}"/>
                    </td></tr>
                <tr>
                    <th>allow：</th><td>
                        <select id="allow-picker">
                            <option value='alaw'>alaw</option>
                            <option value='ulaw'>ulaw</option>
                            <option value='g723'>g723</option>
                            <option value='g729'>g729</option>
                        </select>
                    </td></tr>
                <tr><th>&nbsp;</th><td>
                        <input type="text" name="allow" placeholder="请选择allow"
                               value="{$data.allow|default='g729,alaw,ulaw,g723'}" title="请选择allow!"/>
                    </td></tr>
            </table>
        </fieldset>
        <input type='hidden' name='id' value='{$data.id}'/>
    </form>
</block>
<block name="body_after_block">
    <script type="text/javascript" src="__THEME__Script/trunk-edit.js"></script>
    <script type="text/javascript">
        $('.optional legend').click(function(){
            var $this=$(this);
            var tog=$this.find('i').text();
            if('[+]'==tog){
                $this.parent().find('.optional_content').show();
                $this.find('i').text('[-]');
            }else{
                $this.parent().find('.optional_content').hide();
                $this.find('i').text('[+]');
            }
        })
        item_form.resize_owner_dialog({width: 380});
        // 设置主键控件状态
        if ('' != '{$data.username}') {
            $('input[name="username"], input[name="account"]').attr("readonly", true);
        }
        ajax_load_options({selector: 'select[name="siteID"]', def_option: '选择租户'});
        $('input[name="password"]').val('{$data.password}');
        $('select[name="type"] option[value="{$data.type}"]').prop('selected', true);
        $('select[name="dtmfmode"] option[value="{$data.dtmfmode}"]').prop('selected', true);
        $('input[name="regMode"][value="{$data.regMode}"]').prop('checked', true);
        $('input[name="nat"][value="{$data.nat}"]').prop('checked', true);
    </script>
</block>